package com.umeox.watch.moto.launcher.bean;

import android.os.Parcel;
import android.os.Parcelable;

import java.util.LinkedHashSet;
import java.util.Objects;

/**
 * @author zl
 * @date 2018/8/3
 */

public class NotificationBean implements Parcelable {
    /*语聊*/
    public static final int TYPE_CHAT = 1;
    /*联系人*/
    public static final int TYPE_CALL = 2;
    /*陌生人*/
    public static final int TYPE_CALL_UNKNOWN = 3;
    /*PTT语聊*/
    public static final int TYPE_PTT_CHAT = 4;
    //通知类型
    private int type;
    /**
     * 联系人id或号码
     */
    private String id;
    /**
     * 联系人头像
     */
    private String icon;
    /**
     * 联系人名称
     */
    private String title;
    /**
     * 数量
     */
    private int count;
    /**
     * 时间
     */
    private long time;

    private boolean isGroupMsg;

    private LinkedHashSet<Long> times = new LinkedHashSet<>();

    public int getType() {
        return type;
    }

    public void setType(int type) {
        this.type = type;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getIcon() {
        return icon;
    }

    public void setIcon(String icon) {
        this.icon = icon;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public int getCount() {
        return count;
    }

    public void setCount(int count) {
        this.count = count;
    }

    public long getTime() {
        return time;
    }

    public void setTime(long time) {
        this.time = time;
    }

    public LinkedHashSet<Long> getTimes() {
        return times;
    }

    public void setTimes(LinkedHashSet<Long> times) {
        this.times = times;
    }

    public boolean isGroupMsg() {
        return isGroupMsg;
    }

    public void setGroupMsg(boolean groupMsg) {
        isGroupMsg = groupMsg;
    }

    /**
     * 消息类型和id一样为同一个通知
     *
     * @param o
     * @return
     */
    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof NotificationBean)) return false;

        NotificationBean that = (NotificationBean) o;

        if (type != that.type) return false;
        return Objects.equals(id, that.id);
    }

    @Override
    public int hashCode() {
        int result = type;
        result = 31 * result + (id != null ? id.hashCode() : 0);
        return result;
    }

    @Override
    public String toString() {
        return "NotificationBean{" +
                "type=" + type +
                ", id='" + id + '\'' +
                ", icon='" + icon + '\'' +
                ", title='" + title + '\'' +
                ", count=" + count +
                ", time=" + time +
                ", times=" + times +
                '}';
    }


    public NotificationBean() {
    }


    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeInt(this.type);
        dest.writeString(this.id);
        dest.writeString(this.icon);
        dest.writeString(this.title);
        dest.writeInt(this.count);
        dest.writeLong(this.time);
        dest.writeByte((byte) (this.isGroupMsg ? 1 : 0));
        dest.writeSerializable(this.times);
    }

    protected NotificationBean(Parcel in) {
        this.type = in.readInt();
        this.id = in.readString();
        this.icon = in.readString();
        this.title = in.readString();
        this.count = in.readInt();
        this.time = in.readLong();
        this.isGroupMsg = in.readByte() != 0;
        this.times = (LinkedHashSet<Long>) in.readSerializable();
    }

    public static final Creator<NotificationBean> CREATOR = new Creator<NotificationBean>() {
        @Override
        public NotificationBean createFromParcel(Parcel source) {
            return new NotificationBean(source);
        }

        @Override
        public NotificationBean[] newArray(int size) {
            return new NotificationBean[size];
        }
    };
}
